home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_11_01
/
1101116b
< prev
next >
Wrap
Text File
|
1992-11-01
|
891b
|
42 lines
/* time2.c: Compute a future date */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
main()
{
time_t start, stop;
struct tm *now;
int ndays;
/* Get current date and time */
time(&start);
now = localtime(&start);
/* Enter an interval in days */
fputs("How many days from now? ",stderr);
if (scanf("%d",&ndays) != 1)
return EXIT_FAILURE;
now->tm_mday += ndays;
if (mktime(now) != -1)
printf("New date: %s",asctime(now));
else
puts("Sorry. Can't encode your date.");
/* Calculate elapsed time */
time(&stop);
printf("Elapsed program time in seconds: %f\n",
difftime(stop,start));
return EXIT_SUCCESS;
}
/* Output
How many days from now? 45
New date: Fri Nov 20 12:40:32 1992
Elapsed program time in seconds: 1.000000
*/
/* End of File */